//shoplist.js
const app = getApp();
let QQMapWX = require('../../utils/qqmap-wx-jssdk.min.js');
let qqmapsdk = new QQMapWX({
    key: '4ZPBZ-JXJCX-M5O4R-ZOQDD-7LB6T-XGFET'
}); 

Page({
  data: {
    nowclick: '-1',
    nowAddress: '',
    nowLocal:''
  },
  onLoad: function () {
    let that = this;
    that.firstLocation();
  },
  firstLocation: function () {
    let that = this;
     wx.getLocation({
        type: 'gcj02',
        success: (res) => {
          if (res.errMsg == "getLocation:ok"){
             qqmapsdk.reverseGeocoder({
              location: {
                latitude: res.latitude,
                longitude: res.longitude
              },
              success: function (data) {
                that.setData({
                    nowLocal:data.result.formatted_addresses.recommend,
                    nowAddress:data.result.address
                })
              }
            })
          }
        }
      })
  },
  shopLocation: function () {
    let that = this;
    if (wx.canIUse('button.open-type.openSetting')){
        wx.getSetting({
          success: (res) => {
            if (res.authSetting['scope.userLocation']) {
                wx.getLocation({
                  type: 'gcj02',
                  success: (res) => {
                    if (res.errMsg == "getLocation:ok") {
                      qqmapsdk.reverseGeocoder({
                        location: {
                          latitude: res.latitude,
                          longitude: res.longitude
                        },
                        success: function (data) {
                          that.setData({
                               nowLocal:data.result.formatted_addresses.recommend,
                               nowAddress:data.result.address
                          })
                        }
                      })
                    }
                  }
                })
              } 
          }
      })
    } else {
      wx.showModal({
        title: '提示',
        content: '微信版本过低，无法使用该功能,谢谢！',
        showCancel: false,
        confirmColor: '#fc0636'
      })
    }
  },
  chooseShop: function (e) {
    let that = this;
    that.setData({
      nowclick: e.currentTarget.dataset.id
    }, () => {
        wx.switchTab({
           url: '/pages/homepage/homepage'
        })
    }) 
  }
})
